UNIT FILECHECK;

INTERFACE 
VAR FILEIN:TEXT;
    FILEINPUT:BOOLEAN;
PROCEDURE CHECKINPUTMODE;

IMPLEMENTATION 
PROCEDURE CHECKINPUTMODE;
VAR 
   INFILE:STRING;
   ERROR:INTEGER;
   MODE:CHAR;
BEGIN
     WRITE('DO YOU WANT TO INPUT FROM A F)ILE OR K)EYBOARD-->TYPE F/K ');
     REPEAT
      READ(MODE); WRITELN;
      IF MODE = 'F' THEN
       BEGIN
           WRITELN('ENTER FILENAME');
           REPEAT
                 READLN(INFILE);
                 (*$I- *)
                 RESET(FILEIN,INFILE);
                 (*$I+ *)
                 ERROR:=IORESULT;
                 IF ERROR <> 0 THEN WRITELN('ERROR IN FILENAME-->TYPE AGAIN');
           UNTIL ERROR=0;
           FILEINPUT:=TRUE;
       END
      ELSE IF MODE = 'K' THEN FILEINPUT:=FALSE
      ELSE WRITELN('FILE NOT FOUND--> TYPE AGAIN F/K ');
     UNTIL MODE IN ['F','K'];
     WRITELN; WRITELN; WRITELN;
END;

END.

